<?php $this->load->view('header');?>
<style>
	.report{text-align: center;}
	.report input{height: 35px;width: 310px;}
	.select{display: inline-block;margin: 0 0 0 -137px;position: fixed;}
	.select li{width:310px;height: 35px;line-height: 35px;background-color: #fff;}
	.select li a:hover { background:#545454;display:block;color:#fff;}
	.layui-form-item{line-height: 40px;}
</style>

<body class="childrenBody custom_body">
	<div class="report">
		会员：<input type="text" name="user" onkeyup="show_select(this.value);" placeholder="请输入会员姓名、手机号码"/>
		<div>
			<ul class="select" id="parent"></ul>
		</div>
	</div>

	<div style="display: none;" class="appoint_list">
		<div class="custom_main" style="margin-top: 50px;">
			<fieldset class="layui-elem-field layui-field-title">
			  <legend>会员信息</legend>
			</fieldset>

			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label"> 头像：</label> 
					<div class="layui-input-inline" id="headimg"></div> 
				</div>
				<div class="layui-inline">
					<label class="layui-form-label"> 姓名：</label>
					<div class="layui-input-inline" id="nickname"></div> 
				</div>
				<div class="layui-inline">
					<label class="layui-form-label"> 电话：</label>
					<div class="layui-input-inline" id="mobile"></div> 
				</div>
				<div class="layui-inline">
					<label class="layui-form-label"> 性别：</label>
					<div class="layui-input-inline" id="sex"></div> 
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label"> 备注：</label> 
					<div class="layui-input-block" id="remarks"></div> 
				</div>
			</div>
		</div>

		<div class="custom_main" style="margin-top: 50px;">
			<fieldset class="layui-elem-field layui-field-title">
			  <legend>签到</legend>
			</fieldset>

			<div class="layui-form news_list">
				<table class="layui-table" lay-even="" lay-skin="line">
				    <thead>
						<tr>
							<th>课程</th>
							<th>卡名称</th>
							<th>费用</th>
							<th>场馆</th>
							<th>教练</th>
							<th>上课时间</th>
							<th>操作</th>
						</tr> 
				    </thead>
					<tbody class="goods_content" id="view"></tbody>
				</table>
			</div>
		</div>
	</div>

	<script type="text/javascript">

			layui.config({
		version: true
	}).use(['layer'],function(){
		var layer = parent.layer === undefined ? layui.layer : parent.layer;

	});


		function show_select(val)
		{
			$.get('admin.php/Report/get_user_list',{user:val}, function(data) 
			{
				var len = data.list.length;
				var htm = '';
				if (len > 0) {
					for (var i = 0; i < len; i++) {
						htm += '<li><a href="javascript:;" onclick="user_appoint(this,'+data.list[i].id+')">'+data.list[i].nickname+'('+data.list[i].mobile+')</a></li>';
					}
				}

				$('#parent').html(htm);

				$('#parent').css('display','inline-block');
				
			},'JSON');

		}


		function user_appoint(_this,uid)
		{
			 $("input[name='user']").val($(_this).text());
			 $('#parent').hide();

			 $.get('admin.php/Report/appoint_list',{user_id:uid}, function(data) 
			 {
			 	if (data.status == 200) 
			 	{
			 		//会员基本信息
			 		if (data.list.headimg) {
			 			$('#headimg').html('<img src="'+data.list.headimg+'" style="width: 30px;border-radius: 100%;height: 30px;">');
			 		}else{
			 			$('#headimg').html('<img src="plugins/layui/images/user_img.png" style="width: 30px;border-radius: 100%;">');
			 		}
			 		$('#nickname').html(data.list.nickname);
			 		$('#mobile').html(data.list.mobile);
			 		$('#sex').html(data.list.sex);
			 		$('#remarks').html(data.list.remarks);

			 		//预约列表
			 		var lis = '';
			 		for (var i = 0; i < data.list.appoint_list.length; i++) 
			 		{	
			 			lis += '<tr>';
			 			lis += '<td>'+data.list.appoint_list[i].course_name+'</td>';
			 			lis += '<td>'+data.list.appoint_list[i].card_name+'</td>';
			 			lis += '<td>'+data.list.appoint_list[i].price+'</td>';
			 			lis += '<td>'+data.list.appoint_list[i].shop_name+'</td>';
			 			lis += '<td>'+data.list.appoint_list[i].coach_name+'</td>';
			 			lis += '<td>'+data.list.appoint_list[i].sdate+ ' ' + data.list.appoint_list[i].stime +'</td>';
			 			lis += '<td id="'+data.list.appoint_list[i].id+'"><a class="layui-btn layui-btn-normal layui-btn-mini" title="取消签到" onclick="report_appoint('+data.list.appoint_list[i].id+')"><i class="layui-icon">&#xe605;</i>签到</a></td>';
			 			lis += '</tr>';
			 		}
	
			 		$('#view').html(lis);

			 		$('.appoint_list').show();
			 	}
			 	
			 },'JSON');
		}


		//签到
		function report_appoint(id)
		{
			$.get('admin.php/Report/insert_user_appoint',{aid:id}, function(data) 
			{
				if (data.status == 200) {
					layer.msg(data.message, {icon:1});
					$('#'+id).html('已签到');
				}else{
					layer.msg(data.message, {icon:2});
				}

			},'JSON');
		}



	</script>

</body>
</html>